<?php
$table_source = $old_nav_db_config['DB_PREFIX'].'user';
$table_target = $db_config['DB_PREFIX'].'user';

if($begin == 0)
	$db_target->query("TRUNCATE $table_target");

$data_num = $db_source->query('SELECT COUNT(*) as num FROM '.$table_source.' WHERE status = 1');
if(count($data_num) > 0)
	$data_num = $data_num[0]['num'];
else
	$data_num = 0;
	
$is_complete = false; 

if($data_num > $begin)
{
	$limit = $data_num - $begin;
	if($limit > 1000)
		$limit = 1000;
		
	$data_list = $db_source->query("SELECT * FROM $table_source LIMIT ".$begin.','.$limit);
	showjsmessage("开始转换数据表　user $begin 到 $limit 行");
	$data_count = count($data_list);
	$fields = array_keys($data_list[0]);
	$start_sql = "INSERT INTO $table_target ( `" . implode('`, `', $fields) . '` ) VALUES ';
	
	for($j=0; $j< $data_count; $j++)
	{
		$data = $data_list[$j];
		$record = array_map('dumpEscapeString', $data);//过滤非法字符
		$sql = $start_sql . ' ('. implodeInsertValues($record) .')';
		$db_target->query($sql);
	}
	
	showjsmessage("转换数据表　user $begin 到 $limit 行  成功");
	
	if($limit < 1000)
		$is_complete = true; 
	else
		showjsmessage(U('Index/convert',array('table'=>'user','begin'=>$begin + $limit)),5);
}
else
	$is_complete = true;

if($is_complete)
{
	@unlink(ROOT_PATH.'public/convert_temp.php');
	@file_put_contents($this->install_lock,"");
	@file_put_contents($this->convert_lock,"");
	@mkdir(ROOT_PATH."admin/Runtime/",0777);
	showjsmessage("转换成功",4);
}
?>